package com.ruoyi.web.controller.tool;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bnt.domain.BntArticleinfo;
import com.ruoyi.bnt.domain.BntCourse;
import com.ruoyi.bnt.domain.BntCourseissue;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.service.ISysDictDataService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("获取课程模块数据")
@RestController
@RequestMapping("/bnt/api/course")
public class CourseController extends BaseController {
    @Autowired
    private com.ruoyi.bnt.service.IBntCourseService bntCourseService;

    @Autowired
    private com.ruoyi.bnt.service.IBntCourseissueService bntCourseissueService;

    @Autowired
    private com.ruoyi.bnt.service.IBntArticleinfoService bntArticleinfoService;

    @Autowired
    private com.ruoyi.bnt.service.IBntCourseinfoService bntCourseinfoService;


    @ApiOperation("获取课程列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageSize", value = "每页显示条数", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageNum", value = "当前显示页数", required = true, dataType = "int", paramType = "query")
    })
    @GetMapping("/list")
    public TableDataInfo list(int pageSize, int pageNum)
    {
        com.ruoyi.bnt.domain.BntCourse bntCourse =  new com.ruoyi.bnt.domain.BntCourse();
        PageHelper.startPage(pageNum,pageSize);
        List<com.ruoyi.bnt.domain.BntCourse> list = bntCourseService.selectBntCourseListDic(bntCourse);
        return getDataTable(list);
    }

    @ApiOperation("根据id,courseType获取课程详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "课程记录id", required = true, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "courseType", value = "课程类型", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/info")
    public BntCourseissueEntity info(String id,String courseType)
    {
        BntCourseissueEntity bntCourseissueEntity = new BntCourseissueEntity();
        com.ruoyi.bnt.domain.BntCourse bntSpecialcolumn = bntCourseService.selectBntCourseById(id);
        bntCourseissueEntity.setBntCourse(bntSpecialcolumn);
        if(courseType.equals("course_article")){
            BntArticleinfo bntArticleinfo = new BntArticleinfo();
            bntArticleinfo.setParentId(id);
            bntCourseissueEntity.setBntArticleinfo(bntArticleinfoService.selectBntArticleinfoList(bntArticleinfo));
        }else if(courseType.equals("course_video")){
            BntCourseissue bntCourseissue = new BntCourseissue();
            bntCourseissue.setParentId(id);
            bntCourseissueEntity.setBntCourseissue(bntCourseissueService.selectBntCourseissueList(bntCourseissue));
        }
        return bntCourseissueEntity;
    }

    @ApiOperation("根据id获取课程文章详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "课程文章记录id", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/article/detail")
    public com.ruoyi.bnt.domain.BntArticleinfo articleDetail(String id)
    {
        com.ruoyi.bnt.domain.BntArticleinfo bntArticleinfo = new com.ruoyi.bnt.domain.BntArticleinfo();
        bntArticleinfo = bntArticleinfoService.selectBntArticleinfoById(id);
        //访问量加一
        bntArticleinfoService.addVisitNum(id);
        return bntArticleinfo;
    }

//    @ApiOperation("根据id获取课程视频期数列表信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "课程视频期数记录id", required = true, dataType = "String", paramType = "query")
//    })
//    @GetMapping("/issue/detail")
//    public List<com.ruoyi.bnt.domain.BntCourseissue> issueDetail(String id)
//    {
//        com.ruoyi.bnt.domain.BntCourseissue bntCourseissue = new com.ruoyi.bnt.domain.BntCourseissue();
//        bntCourseissue.setParentId(id);
//        List<BntCourseissue> list = bntCourseissueService.selectBntCourseissueList(bntCourseissue);
//        return list;
//    }

    @ApiOperation("根据id获取课程视频列表信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "课程视频期数记录id", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/issue/video/info")
    public List<com.ruoyi.bnt.domain.BntCourseinfo> issueVideoInfo(String id)
    {
        com.ruoyi.bnt.domain.BntCourseinfo bntCourseinfo = new com.ruoyi.bnt.domain.BntCourseinfo();
        bntCourseinfo.setParentId(id);
        //访问量加一
        //bntCourseinfoService.addVisitNum(id);
        return bntCourseinfoService.selectBntCourseinfoList(bntCourseinfo);
    }

    @ApiOperation("根据id获取课程视频详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "课程视频期数记录id", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping("/issue/video/detail")
    public com.ruoyi.bnt.domain.BntCourseinfo issueVideoDetail(String id)
    {
        com.ruoyi.bnt.domain.BntCourseinfo bntCourseinfo = new com.ruoyi.bnt.domain.BntCourseinfo();
        bntCourseinfo = bntCourseinfoService.selectBntCourseinfoById(id);
        //访问量加一
        bntCourseinfoService.addVisitNum(id);
        return bntCourseinfo;
    }
}

@ApiModel("课程视频、文章详情实体")
class BntCourseissueEntity{
    @ApiModelProperty("主体")
    private com.ruoyi.bnt.domain.BntCourse bntCourse;

    @ApiModelProperty("期数详情")
    private List<com.ruoyi.bnt.domain.BntCourseissue> bntCourseissue;

    @ApiModelProperty("文章详情")
    private List<com.ruoyi.bnt.domain.BntArticleinfo> bntArticleinfo;

    public BntCourse getBntCourse() {
        return bntCourse;
    }

    public void setBntCourse(BntCourse bntCourse) {
        this.bntCourse = bntCourse;
    }

    public List<BntCourseissue> getBntCourseissue() {
        return bntCourseissue;
    }

    public void setBntCourseissue(List<BntCourseissue> bntCourseissue) {
        this.bntCourseissue = bntCourseissue;
    }

    public List<BntArticleinfo> getBntArticleinfo() {
        return bntArticleinfo;
    }

    public void setBntArticleinfo(List<BntArticleinfo> bntArticleinfo) {
        this.bntArticleinfo = bntArticleinfo;
    }
}
